package com.fyzk.activity.lottery.jc.football.newJz.data;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;


import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 16/5/2.
 *
 * 积分排名
 */
public class RankingView extends LinearLayout {

    private Context context;
    private CompoundButton.OnCheckedChangeListener listener;

    private RadioButton total_rb;
    private RadioButton home_rb;
    private RadioButton away_rb;
    private TextView tishi_tv;
    private ListView listView;
    private List<JCZQ_RankingResponse.DataBean> infos = new ArrayList<>();
    private RankingAdapter adapter;

    public RankingView(Context context, AttributeSet attrs, int defStyle, CompoundButton.OnCheckedChangeListener listener) {
        super(context, attrs, defStyle);
        this.context = context;
        this.listener = listener;

        initView();
    }

    public RankingView(Context context, AttributeSet attrs, CompoundButton.OnCheckedChangeListener listener) {
        this(context, attrs, 0, listener);
    }

    public RankingView(Context context, CompoundButton.OnCheckedChangeListener listener) {
        this(context, null, listener);
    }

    public void initView(){
        View.inflate(context, R.layout.jc_ranking_view, this);
        total_rb = (RadioButton) findViewById(R.id.jc_ranking_rb_total);
        home_rb = (RadioButton) findViewById(R.id.jc_ranking_rb_home);
        away_rb = (RadioButton) findViewById(R.id.jc_ranking_rb_away);

        total_rb.setOnCheckedChangeListener(this.listener);
        home_rb.setOnCheckedChangeListener(this.listener);
        away_rb.setOnCheckedChangeListener(this.listener);

        tishi_tv = (TextView) findViewById(R.id.jc_ranking_tishi);

        listView = (ListView) findViewById(R.id.jc_ranking_listview);
        adapter = new RankingAdapter(getContext(), infos);
        listView.setAdapter(adapter);
        listView.setItemsCanFocus(false);
    }

    public void setInfos(List<JCZQ_RankingResponse.DataBean> infos){
        this.infos = infos;
        if (this.infos.size() == 0) {
            tishi_tv.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
        } else {
            tishi_tv.setVisibility(View.GONE);
            listView.setVisibility(View.VISIBLE);
            this.adapter.setInfos(this.infos);
        }
    }


}
